package util

import entity.PbcEbookEntity

object MyWebUtil {

    fun getSonListHtml(parent: PbcEbookEntity, sonList: List<PbcEbookEntity>): String {
        val fatherLong = parent.path.split("/").size

        //动态生成目录图
        val htmlStr = StringBuilder()
        htmlStr.append("<html><head>")
        htmlStr.append("<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=UTF-8\\\">")
        htmlStr.append("<title>${parent.name}</title>")
        htmlStr.append("<style>h2{ font-family: Helvetica, 'Hiragino Sans GB', '微软雅黑', 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; text-align:center; margin: font-weight:bold; }</style>")
        htmlStr.append("</head>")
        htmlStr.append("<body class=b1>")

        htmlStr.append("<span><h2>${parent.name}</h2></span>")

        htmlStr.append("<span><ul>")
        sonList.filter { it.path.split("/").size <= fatherLong + 1 }
                .forEach { htmlStr.append("<li>${it.name}</li>") }
        htmlStr.append("</ul><span>")
        htmlStr.append("</body></html>")

        return htmlStr.toString()
    }
}